package com.olddriver.crm.service.impl;

import com.olddriver.crm.domain.Carinformation;
import com.olddriver.crm.mapper.CarinformationMapper;
import com.olddriver.crm.page.PageResult;
import com.olddriver.crm.query.CarinformationQueryObject;
import com.olddriver.crm.service.ICarinformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class CarinformationServiceImpl implements ICarinformationService{

    @Autowired
    private CarinformationMapper carinformationMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return carinformationMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Carinformation record) {
        return carinformationMapper.insert(record);
    }

    @Override
    public Carinformation selectByPrimaryKey(Long id) {
        return carinformationMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Carinformation> selectAll() {
        return carinformationMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(Carinformation record) {
        return carinformationMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageResult query(CarinformationQueryObject qo) {
       int total = carinformationMapper.queryForTotal(qo);
       if(total ==0){
           return new PageResult(total, Collections.emptyList());
       }

        return new PageResult(total,carinformationMapper.queryForRows(qo));
    }


    @Override
    public void changeState(Long id) {
        carinformationMapper.changeState(id);
    }
}
